<template>
  <input type="text" placeholder="请输入员工姓名" v-model="user.name">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="user.position">
  <button @click="f">添加员工</button>
  <table border="1px">
    <th>编号</th>
    <th>姓名</th>
    <th>工资</th>
    <th>岗位</th>
    <tr v-for="(e,i) in userArr">
      <td>{{i+1}}</td>
      <td>{{e.name}}</td>
      <td>{{e.salary}}</td>
      <td>{{e.position}}</td>
    </tr>
  </table>
</template>
<script setup>
  import {ref} from "vue";

  const user = ref({
    name: '',
    salary:'',
    position: ''
  });
  const userArr = ref([]);
  const f = () => {
    if(user.value.name=='' || user.value.salary=='' || user.value.position==''){
      alert('请输入完整信息');
      return;
    }
    userArr.value.push(user.value);
    user.value={};
  }
</script>


<style scoped>

</style>